package com.jiuwan.gamepass.controller;

import com.jiuwan.gamepass.dao.TotalDao;
import com.jiuwan.gamepass.dto.appJson.TotalPackageJson;
import com.jiuwan.gamepass.dto.appJson.TotalUrlListJson;
import com.jiuwan.gamepass.pojo.Total;
import com.jiuwan.gamepass.service.impl.SDKUploadServiceImpl;
import com.jiuwan.gamepass.utils.MyCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * @version 1.0
 * 功能目的描述 ：用于   SDK部分文件的上传等功能   ========>>>>>>>>>>>
 * @author： pang-yun
 * @date： 2021-06-11 15:36
 */

@Controller
@RequestMapping("sdk")
public class SDKUploadController {

    @Autowired
    private SDKUploadServiceImpl sdkUploadService;

    @Autowired
    private TotalDao totalDao;

    //总接口
    @RequestMapping("total")
    @ResponseBody
    public TotalPackageJson totalLogin(String appID,
                                       MultipartFile[] sdks,
                                       MultipartFile sdkController,
                                       MultipartFile[] icons,
                                       MultipartFile background,
                                       MultipartFile[] materials,
                                       String size
    ) {

        sdkUploadService.uploadFile(sdks, appID);
        sdkUploadService.upLoadFile(sdkController, appID);
        sdkUploadService.uploadIcon(icons, appID);
        sdkUploadService.uploadBackGround(background, appID, size);
        sdkUploadService.uploadMaterial(materials, appID);

        Total total = totalDao.selectByAppID(appID);

        TotalPackageJson totalPackageJson = new TotalPackageJson();
        totalPackageJson.setCode(MyCode.SUCCESS_CODE);
        totalPackageJson.setMsg(MyCode.SUCCESS_MSG);

        HashMap<Object, Object> map = new HashMap<>();
        ArrayList<Object> list = new ArrayList<>();

        list.add(total);
        totalPackageJson.setTotalPackages(list);
        return totalPackageJson;
    }




    //上传多文件
    @RequestMapping("upload")
    @ResponseBody
    public TotalPackageJson upload(MultipartFile[] sdks, String appID) {
        TotalPackageJson totalPackageJson = sdkUploadService.uploadFile(sdks, appID);
        return totalPackageJson;
    }

    @RequestMapping("uploadIcon")
    @ResponseBody
    public TotalPackageJson uploadIcon(MultipartFile[] icons, String appID) {
        TotalPackageJson totalPackageJson = sdkUploadService.uploadIcon(icons, appID);
        return totalPackageJson;
    }

    //上传SDKController
    @RequestMapping("sdkController")
    @ResponseBody
    public TotalPackageJson uploadSDKController(MultipartFile sdkController, String appID) {
        TotalPackageJson totalPackageJson = sdkUploadService.upLoadFile(sdkController, appID);
        return totalPackageJson;
    }

    //上传唯一的backGround
    @RequestMapping("backGround")
    @ResponseBody
    public TotalPackageJson uploadBackGround(MultipartFile background, String appID, String size) {
        TotalPackageJson totalPackageJson = sdkUploadService.uploadBackGround(background, appID, size);
        return totalPackageJson;
    }

    //上传material素材
    @RequestMapping("material")
    @ResponseBody
    public TotalPackageJson uploadMaterial(MultipartFile[] materials, String appID) {
        TotalPackageJson totalPackageJson = sdkUploadService.uploadMaterial(materials, appID);
        return totalPackageJson;
    }


    //------------------------------------------------独立上传操作------------------------------------

    //多文件上传
    @RequestMapping("manyFileUpload")
    @ResponseBody
    public TotalPackageJson manyFileUpload(MultipartFile[] files) {
        TotalPackageJson totalPackageJson = sdkUploadService.uploadManyFile(files);
        return totalPackageJson;
    }

    //单文件上传
    @RequestMapping("singleFileUpload")
    @ResponseBody
    public TotalPackageJson singleFileUpload(MultipartFile file) {
        TotalPackageJson totalPackageJson = sdkUploadService.uploadSingleFile(file);
        return totalPackageJson;
    }

    //多图片上传
    @RequestMapping("manyImageUPload")
    @ResponseBody
    public TotalPackageJson manyImageUpload(MultipartFile[] images, String size) {
        TotalPackageJson totalPackageJson = sdkUploadService.uploadManyImage(images, size);
        return totalPackageJson;
    }

    //单张图片上传
    @RequestMapping("singleImageUPload")
    @ResponseBody
    public TotalPackageJson singleImageUpload(MultipartFile image, String size) {
        TotalPackageJson totalPackageJson = sdkUploadService.uploadSingleImage(image, size);
        return totalPackageJson;
    }


    //将各文件地址放到total表中
    @RequestMapping("setAddressInTotal")
    @ResponseBody
    public TotalPackageJson setAddressInTotal(String appID,
                                              String sdk,
                                              String sdkController,
                                              String icons,
                                              String backGround,
                                              String materials){
        TotalPackageJson totalPackageJson = sdkUploadService.setAddressInTotal(appID, sdk, sdkController, icons, backGround, materials);
        return totalPackageJson;
    }


    //----------------------------将各个接口的详细信息返回，用于后续的下载删除等操作--------------------


    //将total的url返回
    @RequestMapping("urlPathTotal")
    @ResponseBody
    public TotalUrlListJson urlPath(String appId){
        TotalUrlListJson totalUrlListJson = sdkUploadService.urlPath(appId);
        return totalUrlListJson;
    }



}
